package com.game.doudizhu.repository;

import com.game.doudizhu.model.GameRoom;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;

@Repository
public interface GameRoomRepository extends JpaRepository<GameRoom, Long> {
    List<GameRoom> findByStatusAndPlayerCountLessThan(String status, Integer maxPlayers);

    @Query("SELECT r FROM GameRoom r JOIN r.players p WHERE p.id = :playerId")
    Optional<GameRoom> findByPlayerId(@Param("playerId") Long playerId);
    long countByStatus(String status);
    List<GameRoom> findByStatus(String status);

}